#!/bin/sh

# llvm source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/llvm-7.1.0.src.tar.xz

# clang source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/cfe-7.1.0.src.tar.xz

# compiler-rt source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/compiler-rt-7.1.0.src.tar.xz

# libc++ source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/libcxx-7.1.0.src.tar.xz

# libc++abi source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/libcxxabi-7.1.0.src.tar.xz

# libunwind source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/libunwind-7.1.0.src.tar.xz

# lld source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/lld-7.1.0.src.tar.xz

# lldb source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/lldb-7.1.0.src.tar.xz

# openmp source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/openmp-7.1.0.src.tar.xz

# polly source
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/polly-7.1.0.src.tar.xz

# clang-tools-extra
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/clang-tools-extra-7.1.0.src.tar.xz

sudo yum install ncurses-devel
sudo yum install libedit-devel
sudo yum install swig

tar xfv llvm-7.1.0.src.tar.xz

cd llvm-7.1.0.src/

mkdir -p tools/clang
mkdir -p tools/clang/tools/extra
mkdir -p tools/lld
mkdir -p tools/lldb
mkdir -p tools/polly
mkdir -p projects/compiler-rt
mkdir -p projects/libcxx
mkdir -p projects/libcxxabi
mkdir -p projects/libunwind
mkdir -p projects/openmp

tar xfv ../cfe-7.1.0.src.tar.xz -C tools/clang --strip-components=1
tar xfv ../clang-tools-extra-7.1.0.src.tar.xz -C tools/clang/tools/extra --strip-components=1
tar xfv ../lld-7.1.0.src.tar.xz -C tools/lld --strip-components=1
tar xfv ../lldb-7.1.0.src.tar.xz -C tools/lldb --strip-components=1
tar xfv ../polly-7.1.0.src.tar.xz -C tools/polly --strip-components=1
tar xfv ../compiler-rt-7.1.0.src.tar.xz -C projects/compiler-rt --strip-components=1
tar xfv ../libcxx-7.1.0.src.tar.xz -C projects/libcxx --strip-components=1
tar xfv ../libcxxabi-7.1.0.src.tar.xz -C projects/libcxxabi --strip-components=1
tar xfv ../libunwind-7.1.0.src.tar.xz -C projects/libunwind --strip-components=1
tar xfv ../openmp-7.1.0.src.tar.xz -C projects/openmp --strip-components=1

mkdir build
cd build
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_BUILD_DOCS=OFF

make -j4
sudo make install/strip
